package com.atguigu.day12.comparable05.c1;

public class Person implements Comparable {
    String name;
    char gender;
    double salary;
    int age;
    //按照薪水比 Object o = p2;
    public int compareTo(Object o) {
        Person p = (Person) o;
        //this:p1   o:p2
       // return (int)(this.salary-p.salary);
        if(this.salary>p.salary){
            return 1;
        }else if(this.salary<p.salary){
            return -1;
        }
        return 0;
    }

    //Object o = p2;
 /*   public int compareTo(Object o) {
 //todo 按照年龄比
        //this: p1
        Person p =(Person) o;
        return this.age-p.age;
    }*/
    public Person(String name, char gender, double salary, int age) {
        this.name = name;
        this.gender = gender;
        this.salary = salary;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", gender=" + gender +
                ", salary=" + salary +
                ", age=" + age +
                '}';
    }



}
